package com.cat.dynamicPlanning02;

import java.util.HashMap;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/longest-arithmetic-subsequence-of-given-difference/description/
 * @create 2025/9/30 15:47
 * @since JDK17
 */

public class Solution09 {
    public int longestSubsequence(int[] arr, int difference) {
        HashMap<Integer, Integer> map = new HashMap<>();
        int ans = 1, n = arr.length;
        for (int i = 0; i < n; i++) {
            int cnt = map.getOrDefault(arr[i] - difference, 0) + 1;
            map.put(arr[i], cnt);
            ans = Math.max(ans, cnt);
        }

        return ans;
    }
}
